package com.lmx.wuzhangshao.util;

import android.content.Context;
import android.content.SharedPreferences;

import androidx.annotation.NonNull;

/**
 * @author Leung
 * @date 2020/8/18 19:39
 */
public class SharedPreUtil {

    public static final String CONFIG_FILE_NAME = "App_Config";


    public static String getString(@NonNull Context context, String key, String defValue) {
        SharedPreferences sp = context.getSharedPreferences(CONFIG_FILE_NAME, Context.MODE_PRIVATE);
        return sp.getString(key, defValue);
    }

    public static void saveString(@NonNull Context context, String key, String value) {
        SharedPreferences sp = context.getSharedPreferences(CONFIG_FILE_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putString(key, value);
        editor.apply();
    }

    public static boolean getBoolean(@NonNull Context context, String key, boolean defValue) {
        SharedPreferences sp = context.getSharedPreferences(
                CONFIG_FILE_NAME, Context.MODE_PRIVATE);
        return sp.getBoolean(key, defValue);
    }

    public static void saveBoolean(@NonNull Context context, String key, Boolean value) {
        SharedPreferences sp = context.getSharedPreferences(
                CONFIG_FILE_NAME, Context .MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putBoolean(key, value);
        editor.apply();
    }

    public static int getInt(@NonNull Context context, String key, int defValue) {
        SharedPreferences sp = context.getSharedPreferences(CONFIG_FILE_NAME, Context
                .MODE_PRIVATE);
        return sp.getInt(key, defValue);
    }

    public static void saveInt(@NonNull Context context, String key, int value) {
        SharedPreferences sp = context.getSharedPreferences(
                CONFIG_FILE_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putInt(key, value);
        editor.apply();
    }


    public static Long getLong(@NonNull Context context, String key, Long defValue) {
        SharedPreferences sp = context.getSharedPreferences(
                CONFIG_FILE_NAME, Context.MODE_PRIVATE);
        return sp.getLong(key, defValue);
    }

    public static void saveLong(@NonNull Context context, String key, Long value) {
        SharedPreferences sp = context.getSharedPreferences(
                CONFIG_FILE_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putLong(key, value);
        editor.apply();
    }


}
